{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Find Subarrays With Equal Sum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: findSubarrays"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #和相等的子数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums</code>&nbsp;，判断是否存在&nbsp;<strong>两个</strong>&nbsp;长度为&nbsp;<code>2</code>&nbsp;的子数组且它们的&nbsp;<strong>和</strong>&nbsp;相等。注意，这两个子数组起始位置的下标必须&nbsp;<strong>不相同</strong>&nbsp;。</p>\n",
    "\n",
    "<p>如果这样的子数组存在，请返回&nbsp;<code>true</code>，否则返回&nbsp;<code>false</code><em>&nbsp;</em>。</p>\n",
    "\n",
    "<p><strong>子数组</strong> 是一个数组中一段连续非空的元素组成的序列。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>nums = [4,2,4]\n",
    "<b>输出：</b>true\n",
    "<b>解释：</b>元素为 [4,2] 和 [2,4] 的子数组有相同的和 6 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>nums = [1,2,3,4,5]\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>没有长度为 2 的两个子数组和相等。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>nums = [0,0,0]\n",
    "<b>输出：</b>true\n",
    "<b>解释：</b>子数组 [nums[0],nums[1]] 和 [nums[1],nums[2]] 的和相等，都为 0 。\n",
    "注意即使子数组的元素相同，这两个子数组也视为不相同的子数组，因为它们在原数组中的起始位置不同。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= nums.length &lt;= 1000</code></li>\n",
    "\t<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [find-subarrays-with-equal-sum](https://leetcode.cn/problems/find-subarrays-with-equal-sum/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [find-subarrays-with-equal-sum](https://leetcode.cn/problems/find-subarrays-with-equal-sum/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[4,2,4]', '[1,2,3,4,5]', '[0,0,0]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        set1=set()\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i]+nums[i+1] not in set1:\n",
    "                set1.add(nums[i]+nums[i+1])\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        ans = []\n",
    "        for i in range(1, len(nums)):\n",
    "            num = nums[i] + nums[i - 1]\n",
    "            if num not in ans:\n",
    "                ans.append(num)\n",
    "            else:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        for i in range(len(nums)-1):\n",
    "            for j in range(i+1, len(nums)-1):\n",
    "                sum1 = nums[i] + nums[i+1]\n",
    "                sum2 = nums[j] + nums[j+1]\n",
    "                if sum1 == sum2:\n",
    "                    return True\n",
    "        return False\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        # is_ok = False\n",
    "        for i in range(len(nums) - 2):\n",
    "            a = sum(nums[i:i+2])\n",
    "            for j in range(i+1, len(nums) - 1):\n",
    "                if a == sum(nums[j:j+2]):\n",
    "                    # is_ok = True\n",
    "                    # break\n",
    "                    return True\n",
    "        return False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        d = []\n",
    "        for i in range(len(nums) - 1):\n",
    "            cur = nums[i] + nums[i + 1]\n",
    "            if cur not in d:\n",
    "                d.append(cur)\n",
    "            else:\n",
    "                return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        res = set()\n",
    "        for i in range(n-1):\n",
    "            total = nums[i] + nums[i+1]\n",
    "            if total in res:\n",
    "                return True\n",
    "            res.add(total)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n=len(nums)\n",
    "        res=[]\n",
    "        for i in range(n-1):\n",
    "            res+=[nums[i]+nums[i+1]]\n",
    "        if len(set(res))==n-1:\n",
    "            return False\n",
    "        else:\n",
    "            return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        seen = set()\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i-1]+nums[i] in seen:\n",
    "                return True\n",
    "            else:\n",
    "                seen.add(nums[i-1]+nums[i])\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        a=[]\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i]+nums[i+1] in a:\n",
    "                return True\n",
    "            a.append(nums[i]+nums[i+1])\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        for i in range(n-1):\n",
    "            for j in range(i+1,n-1):\n",
    "                if nums[i]+nums[i+1] == nums[j]+nums[j+1]:\n",
    "                    return True\n",
    "                \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        pre = []\n",
    "        for i in range(1,n):\n",
    "            cnt = nums[i]+nums[i-1]\n",
    "            if cnt in pre:\n",
    "                return True\n",
    "            pre.append(cnt)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        seen = set()\n",
    "        for i in range(n - 1):\n",
    "            total = nums[i] + nums[i + 1]\n",
    "            if total in seen:\n",
    "                return True\n",
    "            seen.add(total)\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        for i in range(len(nums)):\n",
    "            for j in range(i + 1, len(nums)):\n",
    "                n1 = nums[i: i + 2]\n",
    "                n2 = nums[j: j + 2]\n",
    "                if sum(n1) == sum(n2) and len(n1) == 2 and len(n2) == 2:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        if len(nums)>2:\n",
    "            for i in range(len(nums)-2):\n",
    "                for j in range(i+1,len(nums)-1):\n",
    "                    if sum(nums[i:i+2])==sum(nums[j:j+2]):\n",
    "                        return True\n",
    "            return False\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        vis = set()\n",
    "        for a, b in pairwise(nums):\n",
    "            x = a + b \n",
    "            if x in vis:\n",
    "                return True\n",
    "            vis.add(x)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "      q=Counter()\n",
    "      n=len(nums)\n",
    "      for i in range(1,n):\n",
    "        if q[nums[i]+nums[i-1]]>0:\n",
    "           return True\n",
    "        q[nums[i]+nums[i-1]]+=1\n",
    "      return False  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        cnt = defaultdict(int)\n",
    "        n = len(nums)\n",
    "        for i in range(1,n):\n",
    "            s = nums[i] + nums[i-1]\n",
    "            cnt[s] += 1\n",
    "            if cnt[s] == 2:\n",
    "                return True \n",
    "        return False "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        s = []\n",
    "        for i in range(len(nums)-1):\n",
    "            s.append(nums[i]+nums[i+1])\n",
    "        return Counter(s).most_common()[0][1]>1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        X=set()\n",
    "        for i in range(len(nums)-1):\n",
    "            cur=nums[i]+nums[i+1]\n",
    "            if cur in X:\n",
    "                return True\n",
    "            X.add(cur)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        a=len(nums);b=[];c=[]\n",
    "        for i in range(1,a):\n",
    "            b.append(nums[i]+nums[i-1])\n",
    "        b.sort()\n",
    "        d=set(b)\n",
    "        c=list(d)\n",
    "        c.sort()\n",
    "        if c==b:\n",
    "            return False\n",
    "        else:\n",
    "            return True    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        if len(nums) == 2:\n",
    "            return False\n",
    "        target = set()\n",
    "        for i in range(len(nums) - 1):\n",
    "            s = nums[i] + nums[i+1]\n",
    "            if s in target:\n",
    "                return True\n",
    "            target.add(s)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        hash = set()\n",
    "        for i, j in pairwise(nums):\n",
    "            if i + j in hash: return True\n",
    "            hash.add(i+j)\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        ans = [None] * (n - 1)\n",
    "        for i in range(n - 1):\n",
    "            x = nums[i] + nums[i + 1]\n",
    "            if x in ans:\n",
    "                return True\n",
    "            ans[i] = x\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        an=[]\n",
    "        flag=False\n",
    "        for i in range(len(nums)-1):\n",
    "            an.append(nums[i]+nums[i+1])\n",
    "        for j in an:\n",
    "            nu=j\n",
    "            for k in an[an.index(j)+1:]:\n",
    "                if j==k:\n",
    "                    flag=True\n",
    "        return flag            \n",
    "                    \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        seen = set()\n",
    "        for i in range(n - 1):\n",
    "            total = nums[i] + nums[i + 1]\n",
    "            if total in seen:\n",
    "                return True\n",
    "            seen.add(total)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        find = set()\n",
    "        for i in range(1, len(nums)):\n",
    "            c = nums[i - 1] + nums[i]\n",
    "            if c in find:\n",
    "                return True\n",
    "            find.add(c)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        vis = set()\n",
    "        for a, b in pairwise(nums):\n",
    "            if (x := a + b) in vis:\n",
    "                return True\n",
    "            vis.add(x)\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        s = set()\n",
    "        for i in pairwise(nums):\n",
    "            if sum(i) in s:\n",
    "                return True\n",
    "            s.add(sum(i))\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        rec_dict = collections.defaultdict(int)\n",
    "        for v, lst_v in zip(nums[1:], nums):\n",
    "            rec_dict[v + lst_v] += 1\n",
    "            if rec_dict[v + lst_v] == 2:\n",
    "                return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        return any(nums[i] + nums[i + 1] == nums[j] + nums[j + 1] for i in range(n - 1) for j in range(i + 1, n - 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        temp = set()\n",
    "        for i in range(n-1):\n",
    "            total = nums[i]+nums[i+1]\n",
    "            if total in temp:\n",
    "                return True\n",
    "            else:\n",
    "                temp.add(total)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        s = set()\n",
    "        for i in range(len(nums)-1):\n",
    "            x = nums[i]+nums[i+1]\n",
    "            if x in s:\n",
    "                return True\n",
    "            s.add(x)\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        s = set()\n",
    "        for i in range(len(nums)-1):\n",
    "            if sum(nums[i:i+2]) not in s:\n",
    "                s.add(sum(nums[i:i+2]))\n",
    "            else:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        ans_set = set()\n",
    "        for i in range(1, len(nums)):\n",
    "            cur_sum = nums[i] + nums[i - 1]\n",
    "            if cur_sum in ans_set:\n",
    "                return True\n",
    "            ans_set.add(cur_sum)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        for i in range(len(nums)-1):\n",
    "            for j in range(i+1,len(nums)-1):\n",
    "                if sum(nums[i:i+2])==sum(nums[j:j+2]):\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        hashtable = set()\n",
    "        n = len(nums)\n",
    "        for i in range(n-1):\n",
    "            s = nums[i]+nums[i+1]\n",
    "            if s in hashtable:\n",
    "                return True\n",
    "            else:\n",
    "                hashtable.add(s)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        temp=[]\n",
    "        for i in range(0,len(nums)-1):\n",
    "            temp.append(nums[i]+nums[i+1])\n",
    "        return not (len(temp)==len(set(temp)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        dic = {}\n",
    "        for i in range(len(nums)-1):\n",
    "            j=i+1\n",
    "            x = nums[i]+nums[j]\n",
    "            dic[x]=dic.get(x,0)+1\n",
    "            if dic[x]==2:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        s=[]\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i]+nums[i+1] in s:\n",
    "                return True\n",
    "            s.append(nums[i]+nums[i+1])\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        res = set()\n",
    "        for i in range(len(nums)-1):\n",
    "            res.add(nums[i] + nums[i+1])\n",
    "        return len(res) != (len(nums)-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        length = len(nums)\n",
    "        count = {}\n",
    "        he = []\n",
    "        for i in range(length - 1):\n",
    "            he.append(nums[i] + nums[i + 1])\n",
    "        for i in he:\n",
    "            if i not in count:\n",
    "                count[i] = 0\n",
    "            count[i] += 1\n",
    "            if count[i] >= 2:\n",
    "                return True\n",
    "        return False\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        sums = set()\n",
    "        for i in range(len(nums) - 1):\n",
    "            s = nums[i] + nums[i + 1]\n",
    "            if s in sums:\n",
    "                return True\n",
    "            sums.add(s)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        # result = []\n",
    "        # for i in range(len(nums)):\n",
    "        #     for j in range(i+1,len(nums)):\n",
    "        #         if j - i ==1:\n",
    "        #             result.append(nums[j]+nums[i])\n",
    "        # return len(result) != len(list(set(result)))\n",
    "        # result = [nums[i]+nums[i+1] for i in range(len(nums)-1)]\n",
    "        # return len(result) != len(list(set(result)))\n",
    "        result = set()\n",
    "        for i in range(len(nums)-1):\n",
    "            temp = nums[i]+nums[i+1]\n",
    "            if temp in result:\n",
    "                return True\n",
    "            else:\n",
    "                result.add(temp)\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        if len(nums) > 2:\n",
    "            for i in range(len(nums)-2): \n",
    "                for s in range(i+1,len(nums)-1):\n",
    "                    if nums[i] +nums[i+1] == nums[s] + nums[s+1]:\n",
    "                        return True \n",
    "            return False\n",
    "        else:\n",
    "            return False\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        save = set()\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i] + nums[i+1] in save:\n",
    "                return True\n",
    "            save.add(nums[i] + nums[i+1])\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        s=set()\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i]+nums[i+1] in s:\n",
    "                return True\n",
    "            s.add(nums[i]+nums[i+1])\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        seen = set()\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i-1]+nums[i] in seen:\n",
    "                return True\n",
    "            else:\n",
    "                seen.add(nums[i-1]+nums[i])\n",
    "        return False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        myset = set()\n",
    "        ln = len(nums)\n",
    "        for i in range(ln - 1):\n",
    "            sum = nums[i] + nums[i + 1]\n",
    "            if sum in myset:\n",
    "                return True\n",
    "            myset.add(sum)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from itertools import pairwise\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        s = set()\n",
    "        for a,b in pairwise(nums):\n",
    "            if a+b in s:\n",
    "                return True\n",
    "            s.add(a+b)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        if n == 2: return False\n",
    "        s = set()\n",
    "        for i in range(n - 1):\n",
    "            temp = nums[i] + nums[i + 1]\n",
    "            if temp not in s: s.add(temp)\n",
    "            else: return True\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n=len(nums)\n",
    "        s=set()\n",
    "        for i in range(n-1):\n",
    "            if nums[i]+nums[i+1] in s:\n",
    "                return True\n",
    "            s.add(nums[i]+nums[i+1])\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        return len(set(map(sum, pairwise(nums)))) < len(nums) - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "\n",
    "        dict1 = {}\n",
    "        for i in range(len(nums)-1):\n",
    "            sum1 = nums[i] + nums[i+1]\n",
    "            if( sum1 not in dict1):\n",
    "                dict1[sum1] = 1\n",
    "            else:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n=collections.Counter([nums[i]+nums[i+1] for i in range(len(nums)-1)])\n",
    "        return any(i>=2 for i in n.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        cnt = {}\n",
    "        for i in range(n-1):\n",
    "            temp = nums[i] + nums[i+1]\n",
    "            if temp not in cnt.keys():\n",
    "                cnt[temp] = 1\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\r\n",
    "        newdic=set()\r\n",
    "        for i in range(len(nums)-1):\r\n",
    "            total = nums[i]+nums[i+1]\r\n",
    "            if total in newdic:\r\n",
    "                return True\r\n",
    "            newdic.add(total)\r\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        if len(nums) == 2:\n",
    "            return False\n",
    "        n = len(nums)\n",
    "        cnt = {}\n",
    "        for i in range(n-1):\n",
    "            temp = nums[i] + nums[i+1]\n",
    "            if temp not in cnt.keys():\n",
    "                cnt[temp] = 1\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        result = []\n",
    "        for i in range(len(nums)):\n",
    "            for j in range(i+1,len(nums)):\n",
    "                if j - i ==1:\n",
    "                    result.append(nums[j]+nums[i])\n",
    "        return len(result) != len(list(set(result)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, a: List[int]) -> bool:\n",
    "        n = len(a)\n",
    "        s = set()\n",
    "        for i in range(n - 1):\n",
    "            sum = a[i] + a[i + 1]\n",
    "            if sum in s :\n",
    "                return True\n",
    "            s.add(sum)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        hash = set()\n",
    "        for i in range(len(nums)):\n",
    "            if i == 0: continue\n",
    "\n",
    "            if nums[i] + nums[i-1] in hash: return True\n",
    "\n",
    "            hash.add(nums[i] + nums[i-1])\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        # 把相邻的两个数的和放到集合里\n",
    "        res=set()\n",
    "        n=len(nums)\n",
    "        for i in range(1,n):\n",
    "            sum=nums[i-1]+nums[i]\n",
    "            if sum in res:\n",
    "                return True\n",
    "            else:\n",
    "                res.add(sum)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findSubarrays(self, nums: List[int]) -> bool:\n",
    "        cur_sum = set()\n",
    "        n = len(nums)\n",
    "        for i in range(1, n):\n",
    "            if nums[i] + nums[i - 1] not in cur_sum:\n",
    "                cur_sum.add(nums[i] + nums[i - 1])\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
